package com.gitee.jjnnzb.designpatterninspring.common.bean;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Administrator
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CommonPage<T> implements Serializable {
    
    @Serial
    private static final long serialVersionUID = -3050319652690913471L;
    
    /**
     * 结果数据
     */
    private List<T> data = new ArrayList<>(1);
    
    /**
     * 数据总量
     */
    private long count = 0;
    
    /**
     * 页码
     */
    private int pageNum = 1;
    
    /**
     * 每页数据量
     */
    private int pageSize = 10;

    public static <T> CommonPage<T> restPage(List<T> data, long total, int pageNum, int pageSize) {
        CommonPage<T> result = new CommonPage<>();
        result.setPageNum(pageNum);
        result.setPageSize(pageSize);
        result.setCount(total);
        result.setData(data);
        return result;
    }
    
    public static <T> CommonPage<T> restPage(List<T> data, long total, int pageNum) {
        CommonPage<T> result = new CommonPage<>();
        result.setPageNum(pageNum);
        result.setPageSize(10);
        result.setCount(total);
        result.setData(data);
        return result;
    }
    
    public static <T> CommonPage<T> restPage(List<T> data, long total) {
        CommonPage<T> result = new CommonPage<>();
        result.setCount(total);
        result.setData(data);
        return result;
    }
}
